package tech.aistar.day01;

import javax.servlet.GenericServlet;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 本类功能:
 *
 * @author cxylk
 * @date 2020/9/15 17:59
 */
@WebServlet(urlPatterns = "/day01/two")
public class TwoServlet extends GenericServlet {
    /**
     * service 方法接收客户端请求
     * service 方法响应数据给客户端
     *
     * http://localhost:8080/lk/day01/two?name=zhangsan
     * @param servletRequest ServletRequest - 封装所有来自于客户端请求的数据
     * @param servletResponse ServletResponse - 所有响应给客户端的数据全部封装到对象中
     * @throws ServletException
     * @throws IOException
     */
    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        String name=servletRequest.getParameter("name");
        System.out.println(name);

        //设置编码
        servletResponse.setContentType("text/html;charset=utf-8");

        //获取文档输出流
        PrintWriter out=servletResponse.getWriter();
        out.println("<!doctype html>");
        out.println("<html>");
        out.println("   <head><meta charset='urf-8'></head>");
        out.println("   <body>");
        out.println("       <p>p段落</p>");
        out.println("       <a href=\"www.baidu.com\">百度</a>");

        out.println("   </body>");
        out.println("</html>");
    }
}
